package com.fone.player.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.fone.player.R;

/**
 * 自定义对话框 需要传入dialog样式文件,dialog布局文件
 * 
 * ps:在调用时注意mcontext报错,参数传入调用该对话框的activity
 * 
 * @author Jason_Zue
 */
public class CustomDialog extends Dialog {

//	public int layoutRes;// 布局文件
//	public Context context;
	private View mView;

	public CustomDialog(Context context) {
		this(context, null);
//		this.context = context;
	}

	/**
	 * 自定义布局的构造方法
	 * 
	 * @param context
	 * @param resLayout
	 */
	public CustomDialog(Context context, View mView) {
		super(context, R.style.comm_alertdialog);
		this.mView = mView;
	}

	/**
	 * 自定义主题及布局的构造方法
	 * 
	 * @param context
	 * @param theme
	 * @param resLayout
	 */
	public CustomDialog(Context context, int theme, int resLayout) {
		super(context, theme);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		if (mView != null)
			this.setContentView(mView);
	}

	public void setButtonsListener(final DialogButtonsListener listener) {
		final Button okBut = (Button) findViewById(R.id.okbut);
		final Button cancleBut = (Button) findViewById(R.id.canclebut);

		android.view.View.OnClickListener onclick = new android.view.View.OnClickListener() {

			@Override
			public void onClick(View v) {
				if (v == okBut) {
					listener.onOKClick();
				} else if (v == cancleBut) {
					listener.onCancleClick();
				}

			}
		};
		okBut.setOnClickListener(onclick);
		cancleBut.setOnClickListener(onclick);

	}

}
